home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d13
/
pcrsep89.arc
/
AVG.BAS
next >
Wrap
BASIC Source File
|
1990-03-21
|
1KB
|
47 lines
' Quick Basic program that sets each cell to the average of its neighborhood
DEFINT A-Z
' $Include: 'CA.BI'
DO
CLS
Rows = 80 ' Assumes an EGA/VGA adapter
Cols = 80 ' and monitor
RowRpt = 4
ColRpt = 8
x% = CAINIT(6, VARPTR(CaArray(0))) 'Initialize the world
CALL CASIZE (Rows, Cols, RowRpt, ColRpt) 'Set its size
RANDOMIZE TIMER
CALL CABORDER(int(rnd * 256)) 'Pick value for invisible border
FOR i = 1 TO Rows
FOR j = 1 TO Cols
k = INT(RND * 256) 'Random value for each cell
CALL CASET(i, j, k)
NEXT j
NEXT i
CASHOW 'Show starting values
DO WHILE INKEY$ = ""
CAGEN 'Loop until user wants out
LOOP
CARESET
CLS
Print "Do it again? ==> ";
DO
Char$ = Ucase$(Input$(1))
Loop until instr("YN",Char$)
LOOP While Char$ = "Y"
END
FUNCTION CACELL% 'Do the work here
sum = 0
for i = NorthWest to SouthEast 'Add up all the neighbors
sum = sum + CaArray(i) ' (including self)
next i
CaCell = sum \ 9 'Become as average as possible
END FUNCTION